﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;
using System.Linq;

namespace ClassLibrary
{
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
    public class AuthorizeEnumAttribute : AuthorizeAttribute
    {
        public new RolesEnum Roles;

        protected override bool AuthorizeCore(HttpContextBase httpContext)
        {
            if (httpContext == null)
                throw new ArgumentNullException("httpContext");

            /*string[] users = Users.Split(',');

            if (!httpContext.User.Identity.IsAuthenticated)
                return false;*/

            if (httpContext.Session["roles"] == null)
                return false;

            var userRoles = (RolesEnum)httpContext.Session["roles"];

            RolesEnum result = userRoles & Roles;

            return result != RolesEnum.None;
        }
    }
}